package schoolsource.gui;

import schoolsource.model.Container;

public class Content {
//    private String text;
    private Container[] contents;
    private String[] accessorNames;

    protected Content() {

    }

    public Content(Container[] container, String[] newAccessorNames) {
        contents = container;
        accessorNames = newAccessorNames;
    }

    public int size() {
        return contents.length;
    }

    public String getRow(int index, int width) {
    	return "<a href=\"\" onClick='return false;'>" + 
    		DisplayString.getTruncatedString(getText(index), width-10, 4)+"</a>";
        //return "<a href=\"\" onClick='return false;'>" + getText(index) + "</a>";
    }

    public String getText(int index) {
        Object returnItem = contents[index];
        try {
            for (int i = 0; i < accessorNames.length; ++i) {
                returnItem = returnItem.getClass().getMethod(accessorNames[i], new Class[] {}).invoke(returnItem, new Object[] {});
            }
        }
        catch (Exception e) {
        }
        return returnItem.toString();
    }

    public boolean useDiv() {
        return true;
    }
}